package com.sunducation.wts.databinding4

import androidx.databinding.ViewDataBinding

class MyAdapter<T> constructor(layout:Int) : BaseAdapter<T>() {
    var layout:Int = layout //代替下方init方法 constructor(layout:Int)为主构造函数

    //    init {
//        主构造函数执行后执行
//        this.layout = layout
//    }
    private lateinit var onItemClickListener: OnItemClickListener

    fun setOnItemClickListener(listener: OnItemClickListener) {
        this.onItemClickListener = listener
    }
    override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
        var binding : ViewDataBinding = holder.dataBinding
        binding.setVariable(BR.myData,data.get(position))
        holder.itemView.setOnClickListener {
            onItemClickListener.onItemClick(holder.itemView,position)
        }
    }

    override fun getItemViewType(position: Int): Int {
        return this.layout
//        return R.layout.server_owner_dash_board_item
    }
}